# 定义SERVER_NAME（对应 pom.xml 的 artifactId 值）和SERVER_PORT（微服务的端口，不指定就默认8080）
SERVER_NAME=my-test
SERVER_PORT=9084

# 停止和删除docker容器
echo "stop and delete container"
CID=$(docker ps | grep "$SERVER_NAME" | awk '{print $1}')
if [ -n "$CID" ]; then
echo "has container，CID=$CID"
docker stop $CID
docker rm $CID

fi
echo "build docker image"
mvn dockerfile:build
echo "current docker images："
docker images | grep $SERVER_NAME
echo "start container----->"
# 微服务的端口映射到 docker 容器的 80 端口
docker run -d -p $SERVER_PORT:8080 --name $SERVER_NAME $SERVER_NAME
echo "start success！"
